import { useSelector } from 'react-redux'
import { ComponentInfoType } from '@/store/modules/componentsReducer'

const useGetComponentInfo = () => {
  const components = useSelector((state: any) => state.components.present)
  const { componentList = [], selectedId, copiedComponent } = components
  const selectedComponent = componentList.find((c: ComponentInfoType) => c.fe_id === selectedId)
  const selectedIndex = componentList.findIndex((c: ComponentInfoType) => c.fe_id === selectedId)

  return { componentList, selectedId, selectedIndex, selectedComponent, copiedComponent }
}

export default useGetComponentInfo
